'use strict'
const path = require('path')
const defaultSettings = require('./src/settings.js')

// 用以支持 gzip 压缩
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']

function resolve(dir) {
    return path.join(__dirname, dir)
}

const name = defaultSettings.title || "VUE项目"

// 设置默认端口
// 如果希望本地预览时修改端口可以使用以下命令
// port = 9528 或者 npm run dev 或者 npm run dev --port = 9000
const port = process.env.port || process.env.npm_config_prt || 9000

// https://cli.vuejs.org/config/
module.exports = {
    publicPath: './',
    // 构建时的输出目录
    outputDir: 'dist',
    // 放置静态资源的目录
    assetsDir: 'static',
    lintOnSave: process.env.NODE_ENV === 'development',
    // 是否为生产环境构建生成 source map？
    productionSourceMap: false,
    devServer: {
        port: port,
        open: true,
        overlay: {
            warnings: false,
            errors: true
        }
    },
    configureWebpack: {
        name: name,
        resolve: {
            alias: {
                '@': resolve('src')
            }
        },
        plugins: [
            new CompressionWebpackPlugin({
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
                threshold: 10240,
                minRatio: 0.8
            })
        ]
    }
}